import { createRouter, createWebHashHistory } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import { staticRoutes, notFoundAndNoPower, dynamicRoutes } from "/@/router/routerList";
import { Session } from "/@/utils/storage";
import { NextLoading } from "/@/utils/loading";

export const routerList = [...staticRoutes, ...dynamicRoutes, ...notFoundAndNoPower];

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: routerList,
});
router.beforeEach(async (to, from, next) => {
  // NextLoading.start();
  NProgress.configure({ showSpinner: false });
  //不需要登录的时候
  next();
  // const token = Session.get("token");
  // if (to.path === "/login" && !token) {
  //   next();
  //   NProgress.done();
  // } else {
  //   if (!token) {
  //     next(`/login?redirect=${to.path}&params=${JSON.stringify(to.query ? to.query : to.params)}`);
  //     Session.clear();
  //     NProgress.done();
  //   } else if (token && to.path === "/login") {
  //     next("/home");
  //     NProgress.done();
  //   } else {
  //     next();
  //   }
  // }
});

// 路由加载后
router.afterEach(() => {
  NProgress.done();
  // NextLoading.done(300);
});

export default router;
